package de.mpii.struct.tree;

import java.util.ArrayList;
import java.util.List;

public class TreeNode<T> {

	private final List<TreeNode<T>> children = new ArrayList<TreeNode<T>>();

	private TreeNode<T> parent = null;

	private T object = null;

	public void add(TreeNode<T> node) {
		children.add(node);
		node.parent = this;
	}

	public List<TreeNode<T>> getChildren() {
		return children;
	}

	public T getObject() {
		return object;
	}

	public boolean isLeaf() {
		return children.isEmpty();
	}

	public boolean isRoot() {
		return parent == null;
	}

	public void setObject(T object) {
		this.object = object;
	}

	@Override
	public String toString() {
		return object != null ? object.toString() : null;
	}

}
